package com.uinnova.springboot.demo.mybatis;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import org.springframework.util.Assert;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 张攀钦
 * @date 2018-12-31-0:24
 * 性别枚举
 */
public enum SexEnum {
    /**
     * @author 张攀钦
     * @date 2018/12/31-1:18
     * 性别
     */

    boy("男"),
    girl("女");
    private String value;

    SexEnum(String value) {
        this.value = value;
    }

    static Map<String, SexEnum> enumMap = new HashMap<>();

    static {
        for (SexEnum type : SexEnum.values()) {
            enumMap.put(type.getValue(), type);
        }
    }

    @JsonValue
    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    @Override
    public String toString() {
        return this.value;
    }

    @JsonCreator
    public static SexEnum getSexEnum(String value) {
        SexEnum sexEnum = enumMap.get(value);
        Assert.notNull(sexEnum,"value 对应的 SexEnum 不存在");
        return sexEnum;
    }

}
